Solution to Exercise 3

Solution to exercise 3.

We'll cover the following

Solution#

Again, the solution will work without using the alias for COUNT(Emp_Id).

Explanation#

The query has two requirements: first, fetch the project-wise count and then sort the result by that count. For a project-wise count, we will be using the COUNT() function to count the number of employees that have been grouped together using the GROUP BY clause. Lastly, for sorting, we will use the ORDER BY clause on the alias of the employee-count.

The slides below help to visualize the solution:

Created with Fabric.js 1.6.0-rc.1 The GROUP BY clause will divide the employees working on same project into different groups. As we can see these two employees work on P1 so they will be grouped together Likewise these two will be grouped together as they work on P2 Then the COUNT() function will count thenumber of employees per project And so on
1 of 2
Exercise 3
Exercise 4
Mark as Completed
Report an Issue